﻿<%@ Page Language="C#" AutoEventWireup="true" EnableViewState="false" CodeBehind="Default.aspx.cs"
    Inherits="Web.View.roleMgr.Default" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>中国云--WebMisDeveloper用户角色权限管理</title>
    <link href="/view/images/Icons/icon.css" rel="stylesheet" type="text/css" />
    <script src="/view/js/Alert.js" type="text/javascript"></script>
    <script type="text/javascript">
        var nodeSeleted = function (node, checked) {

            node.eachChild(function (child) {
                child.ui.toggleCheck(checked);
                child.attributes.checked = checked;
            });
            parentChecked(node, checked);
            //getTasks();
        };
        var nodeState = function (node) {
            var box = node.getUI().checkbox;
            if (box.checked) {
                return 1;
            } else if (box.indeterminate) {
                return 2;
            } else {
                return 3;
            }
        };
        //
        var siblState = function (node) {
            var state = new Array();
            var firstNode = node.parentNode.firstChild;
            if (!firstNode) {
                return false;
            }
            do {
                state.push(nodeState(firstNode));
                firstNode = firstNode.nextSibling;
            } while (firstNode != null)
            return state;
        };
        //
        var parentState = function (node) {
            var state = siblState(node).join();
            if (state.indexOf("1") == -1 && state.indexOf("2") == -1) {
                return -1;
            } else {
                return 1;
            }
        }


        var parentChecked = function (node, checked) {
            var parentNode = node.parentNode;
            if (parentNode == null || parentNode.id == 'root') {
                return false;
            }
            var checkbox = parentNode.getUI().checkbox;
            if (typeof checkbox == 'undefined')
                return false;
            var check = parentState(node);
            if (check == 1) {
                checkbox.indeterminate = false; //半选中状态
                checkbox.checked = true;
            } else if (check == -1) {
                checkbox.checked = false;
                checkbox.indeterminate = false;
            } else {
                checkbox.checked = false;
                checkbox.indeterminate = true;
            }
            parentChecked(parentNode, checked);
        };
        var sn = "";
        function getTasks() {
            var msg = "", selNodes = TreeAllFuns.getChecked();
            //debugger;
            Ext.each(selNodes, function (node) {
                if (node.leaf == true) {
                    if (msg.length > 0) {
                        msg += ",";
                    }
                    msg += node.id ;
                }
            });
            return msg + "," + roleForfun_Grid.getSelectionModel().getSelected().id;
        }
        var GetFunName = function (value) {
            index = AllFun_Store.find("funid", value, 0, false, false);
            if (AllFun_Store.getAt(index).get('fatherid') == "0")
                return "<font color='red'>" + AllFun_Store.getAt(index).get('funname') + "</font>";
            else
                return AllFun_Store.getAt(index).get('funname');
        };
        var GetRoleName = function (value) {
            //debugger;
            index = role_Store.find("roleid", value);
            return role_Store.getAt(index).get('rolename');
        };
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="role_Store" runat="server" OnRefreshData="InfoBind" AutoLoad="true"
        ShowWarningOnFailure="false" OnBeforeStoreChanged="HandleChanges" SkipIdForNewRecords="false"
        RefreshAfterSaving="None">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="roleid">
                <Fields>
                    <ext:RecordField Name="roleid" />
                    <ext:RecordField Name="roleno" />
                    <ext:RecordField Name="rolename" />
                    <ext:RecordField Name="beizhu" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>

    <ext:Store ID="AllFun_Store" runat="server" OnRefreshData="AllFunBind" AutoLoad="true">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="funid">
                <Fields>
                <ext:RecordField Name="funid" />
                    <ext:RecordField Name="funno" />
                    <ext:RecordField Name="funname" />
                    <ext:RecordField Name="fatherid" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>

    <ext:Store ID="rolefun_Store" runat="server" AutoLoad="false">
        <Reader>
            <ext:JsonReader IDProperty="pid">
                <Fields>
                    <ext:RecordField Name="pid" />
                    <ext:RecordField Name="roleid" />
                    <ext:RecordField Name="funid" />
                    <ext:RecordField Name="rolep" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server">
        <Items>
            <ext:FitLayout ID="FitLayout1" runat="server">
                <Items>
                    <ext:GridPanel ID="role_Grid" Layout="fit" TrackMouseOver="true" runat="server" StoreID="role_Store"
                        StripeRows="true" Header="false" Border="false" Collapsible="true">
                        <Plugins>
                            <ext:RowEditor ID="RowEditor1" runat="server" SaveText="更新" CancelText="取消">
                            </ext:RowEditor>
                        </Plugins>
                        <View>
                            <ext:GridView ID="GridView1" runat="server" MarkDirty="false" />
                        </View>
                        <TopBar>
                            <ext:Toolbar ID="Toolbar1" runat="server">
                                <Items>
                                    <ext:Button ID="BtnAdd" runat="server" Text="添加" Icon="Add">
                                        <Listeners>
                                            <Click Handler="#{role_Grid}.insertRecord();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="BtnDelete" runat="server" Text="删除" Icon="Delete">
                                        <DirectEvents>
                                            <Click OnEvent="BtnDel_Click">
                                                <Confirmation ConfirmRequest="true" Title="确认" Message="确实要删除吗?" />
                                                <EventMask ShowMask="true" Msg="正在删除数据，请等候 ..." />
                                            </Click>
                                        </DirectEvents>
                                        <Listeners>
                                            <Click Handler="if(#{role_Grid}.getSelectionModel().getCount()<=0) {TellAlert('请选择要删除的记录');return false;}" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="Button1" runat="server" Text="保存修改" Icon="Disk">
                                        <Listeners>
                                            <Click Handler="#{role_Grid}.save();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="Button3" runat="server" Text="重新加载" Icon="Reload">
                                        <Listeners>
                                            <Click Handler="#{role_Store}.reload();" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="BtnRoleMgr" runat="server" Text="分配权限" Icon="ShieldRainbow">
                                        <ToolTips>
                                            <ext:ToolTip Title="为角色分配功能权限">
                                            </ext:ToolTip>
                                        </ToolTips>
                                        <Listeners>
                                            <Click Handler="#{FunWin}.show();" />
                                        </Listeners>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel ID="ColumnModel1" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn Width="20" />
                                <ext:Column Header="角色ID" Sortable="true" Hidden="true" DataIndex="roleid" />
                                <ext:Column Header="角色编号" Sortable="true" Hidden="true" DataIndex="roleno" />
                                <ext:Column Header="角色名称" Sortable="true" DataIndex="rolename">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false">
                                        </ext:TextField>
                                    </Editor>
                                </ext:Column>
                                <ext:Column Header="角色描述" Width="300" Sortable="true" DataIndex="beizhu">
                                    <Editor>
                                        <ext:TextField runat="server" AllowBlank="false">
                                        </ext:TextField>
                                    </Editor>
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckBoxGrid" runat="server" />
                        </SelectionModel>
                        <LoadMask ShowMask="true" Msg="正在加载..." />
                    </ext:GridPanel>
                </Items>
            </ext:FitLayout>
        </Items>
    </ext:Viewport>
    <ext:Window ID="FunWin" runat="server" Modal="true" Hidden="true" Collapsible="true"
        Maximizable="true" Height="400" Icon="ShieldRainbow" Title="角色功能权限配置" Width="600"
        Layout="column">
        <Items>
            <ext:Panel ID="Panel1" runat="server" Title="系统功能菜单" Width="200">
                <Items>
                    <ext:TreePanel ID="TreeAllFuns" UseArrows="true" AutoScroll="true" Animate="true"
                        EnableDD="true" ContainerScroll="true" AutoHeight="true" Border="false" Header="false"
                        RootVisible="false" runat="server">
                        <Root>
                            <ext:AsyncTreeNode Text="Examples" NodeID="root" Expanded="true" Checked="False" />
                        </Root>
                        <Loader>
                            <ext:PageTreeLoader RequestMethod="GET" OnNodeLoad="GetExamplesNodes" PreloadChildren="true">
                                <EventMask ShowMask="true" Target="Parent" Msg="Loading..." />
                            </ext:PageTreeLoader>
                        </Loader>
                        <Listeners>
                            <CheckChange Handler="nodeSeleted(node,checked);" />
                            <Render Handler="this.getRootNode().expand(true);" Delay="50" />
                        </Listeners>
                    </ext:TreePanel>
                </Items>
            </ext:Panel>
            <ext:Panel ID="Panel2" runat="server" Header="false" ColumnWidth="1">
                <Items>
                <ext:RowLayout ID="RowLayout1" runat="server" Split="true">
                <Rows>
                    <ext:LayoutRow RowHeight="0.4">

                    <ext:GridPanel ID="roleForfun_Grid" TrackMouseOver="true" runat="server"
                        StoreID="role_Store" StripeRows="true" Title="系统角色" Border="false"
                        Collapsible="true">
                        <ColumnModel ID="cmfun" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn Width="20" />
                                <ext:Column Header="角色ID" Sortable="true" Hidden="true" DataIndex="roleid" />
                                <ext:Column Header="角色名称" Sortable="true" DataIndex="rolename"></ext:Column>
                                <ext:Column Header="角色备注" Sortable="true" DataIndex="beizhu">
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <DirectEvents>
                            <RowClick OnEvent="roleForFunGridDBClick">
                                <ExtraParams>
                                    <ext:Parameter Name="id" Value="#{roleForfun_Grid}.store.getAt(rowIndex).get('roleid')"
                                        Mode="Raw" />
                                </ExtraParams>
                                <EventMask ShowMask="true" Msg="正在处理......" />
                            </RowClick>
                        </DirectEvents>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel SingleSelect="true" ID="CheckboxSelectionModel1" runat="server" />
                        </SelectionModel>
                        <LoadMask ShowMask="true" Msg="正在加载..." />
                    </ext:GridPanel>
                    </ext:LayoutRow>
                    <ext:LayoutRow RowHeight="0.6">
                        <ext:GridPanel ID="funOfrole_Grid" Height="100px" TrackMouseOver="true" runat="server"
                        StoreID="rolefun_Store" StripeRows="true" Title="角色功能列表" Border="false"
                        Collapsible="true">
                        <TopBar>
                            <ext:Toolbar ID="Toolbar2" runat="server">
                                <Items>
                                    <ext:Button ID="Button2" runat="server" Text="功能授权" Icon="Add">
                                        <DirectEvents>
                                            <Click OnEvent="BtnGiveFuns_Click">
                                                <EventMask ShowMask="true" Msg="正在操作，请等候 ..." />
                                                <ExtraParams>
                                                    <ext:Parameter Name="id" Value="getTasks()" Mode="Raw" />
                                                </ExtraParams>
                                            </Click>
                                        </DirectEvents>
                                        <Listeners>
                                            <Click Handler="if(#{roleForfun_Grid}.getSelectionModel().getCount()<=0){Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: '请选择被授权用户！', buttons:Ext.Msg.OK});return false;}if(#{TreeAllFuns}.getChecked().length<=0){Ext.Msg.show({icon: Ext.MessageBox.ERROR, msg: '请选择要授予的功能节点！', buttons:Ext.Msg.OK});return false;}" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="Button4" runat="server" Text="删除功能" Icon="Delete">
                                        <DirectEvents>
                                            <Click OnEvent="BtnDelFuns_Click">
                                                <Confirmation ConfirmRequest="true" Title="确认" Message="确实要删除吗?" />
                                                <EventMask ShowMask="true" Msg="正在删除数据，请等候 ..." />
                                            </Click>
                                        </DirectEvents>
                                        <Listeners>
                                            <Click Handler="if(#{funOfrole_Grid}.getSelectionModel().getCount()<=0) {TellAlert('请选择要删除的记录');return false;}" />
                                        </Listeners>
                                    </ext:Button>
                                    <ext:ToolbarSeparator />
                                    <ext:Button ID="Button5" runat="server" Text="0读写/1只读" Icon="WorldEdit">
                                        <DirectEvents>
                                            <Click OnEvent="BtnChangeStatic_Click">
                                                <EventMask ShowMask="true" Msg="正在操作，请等候 ..." />
                                            </Click>
                                        </DirectEvents>
                                        <Listeners>
                                            <Click Handler="if(#{funOfrole_Grid}.getSelectionModel().getCount()<=0) {TellAlert('请选择要删除的记录');return false;}" />
                                        </Listeners>
                                        <ToolTips>
                                            <ext:ToolTip Title="0表示读写功能，1表示只读功能；单击交替变化状态。">
                                            </ext:ToolTip>
                                        </ToolTips>
                                    </ext:Button>
                                </Items>
                            </ext:Toolbar>
                        </TopBar>
                        <ColumnModel ID="ColumnModel2" runat="server">
                            <Columns>
                                <ext:RowNumbererColumn Width="20" />
                                <ext:Column Header="主键" Sortable="true" Hidden="true" DataIndex="pid" />
                                <ext:Column Header="角色名称" Sortable="true" DataIndex="roleid" >
                                    <Renderer Fn="GetRoleName" />
                                </ext:Column>
                                <ext:Column Header="功能模块" Sortable="true" DataIndex="funid">
                                    <Renderer Fn="GetFunName" />
                                </ext:Column>
                                <ext:Column Header="读写" Sortable="true" DataIndex="rolep">
                                </ext:Column>
                            </Columns>
                        </ColumnModel>
                        <SelectionModel>
                            <ext:CheckboxSelectionModel ID="CheckboxSelectionModel2" runat="server" />
                        </SelectionModel>
                        <LoadMask ShowMask="true" Msg="正在加载..." />
                    </ext:GridPanel>
                    </ext:LayoutRow>
                    </Rows>
                    </ext:RowLayout>
                </Items>
            </ext:Panel>
        </Items>
    </ext:Window>
    </form>
</body>
</html>
